/**
 * @Author: Ray丶X
 * @Date: 2020/4/10
 */
var http = require('http');
var fs = require('fs');
var url = require('url');
// var data = {
//   "id": "123",
//   "name": "jack",
//   "message":  "success",
//   "arg": "11111"
// };
//
// var data1 = {
//   "status": "ok",
//   "type":  "account",
//   "message":  "success",
//   "currentAuthority": "admin"
// };

var data2 = {
  "code":  "0",
  "type":  "account",
  "message":  "success",
  "currentAuthority": "admin",
  "result": {
    "name": "Serati Ma",
    "avatar": "https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png",
    "userid": "00000001",
    "email": "antdesign@alipay.com",
    "signature": "海纳百川，有容乃大",
    "title": "交互专家",
    "group": "蚂蚁金服－某某某事业群－某某平台部－某某技术部－UED",
    "tags": [
      {
        "key": "0",
        "label": "很有想法的"
      },
      {
        "key": "1",
        "label": "专注设计"
      }
    ],
    "notifyCount": "12",
    "unreadCount": "11",
    "country": "China",
    "geographic": {
      "province": {
        "label": "浙江省",
        "key": "330000"
      },
      "city": {
        "label": "杭州市",
        "key": "330100"
      }
    },
    "address": "西湖区工专路 77 号",
    "phone": "0752-268888888"
  }
};

var data3 = {
  "code":  "0",
  "type":  "account",
  "message":  "success",
  "currentAuthority": "admin",
  "name": "Serati Ma",
  "avatar": "https://gw.alipayobjects.com/zos/antfincdn/XAosXuNZyF/BiazfanxmamNRoxxVxka.png",
  "userid": "00000001",
  "email": "antdesign@alipay.com",
  "signature": "海纳百川，有容乃大",
  "title": "交互专家",
  "group": "蚂蚁金服－某某某事业群－某某平台部－某某技术部－UED",
  "tags": [
    {
      "key": "0",
      "label": "很有想法的"
    },
    {
      "key": "1",
      "label": "专注设计"
    }
  ],
  "notifyCount": "12",
  "unreadCount": "11",
  "country": "China",
  "geographic": {
    "province": {
      "label": "浙江省",
      "key": "330000"
    },
    "city": {
      "label": "杭州市",
      "key": "330100"
    }
  },
  "address": "西湖区工专路 77 号",
  "phone": "0752-268888888"
};

var res = {
  "code": '0',
  "message": 'success'
};

// 创建服务器
http.createServer( function (request, response) {
  // 解析请求，包括文件名
  var pathname = url.parse(request.url).pathname;
  var str = '';

  // 输出请求的文件名
  console.log("Request for " + pathname + " received.");

  // HTTP 状态码: 200 : OK
  // Content Type: text/html
  response.writeHead(200, {'Content-Type': 'application/json'});

  if (pathname == '/user/login'){
    str = JSON.stringify(data2);
  } else if (pathname == '/currentUser'){
    str = JSON.stringify(data3);
  } else {
    str = JSON.stringify(str);
  }

  response.end(str);




}).listen(3003);

// 控制台会输出以下信息
console.log('Server running at http://127.0.0.1:3003/');
